package com.fx.device.controller.activit;


import com.fx.device.common.util.ReturnMessage;
import com.fx.device.service.activit.ProcessDefinitionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/processDefinition")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class ProcessDefinitionController {


    final private ProcessDefinitionService service;


    //上传bpmn文件，部署流程
    @PostMapping(value = "/uploadStreamAndDeployment")
    public ReturnMessage<Object> uploadStreamAndDeployment(@RequestParam("processFile") MultipartFile multipartFile
            , @RequestParam("deploymentName") String deploymentName) {// 获取上传的文件名


        return service.uploadStreamAndDeployment(multipartFile, deploymentName);

    }


    @PostMapping(value = "/upload")
    public ReturnMessage<Object> upload(HttpServletRequest request, @RequestParam("processFile") MultipartFile multipartFile) {

        return service.upload(multipartFile);
    }


    @PostMapping(value = "/addDeploymentByFileNameBPMN")
    public ReturnMessage<Object> addDeploymentByFileNameBPMN(@RequestParam("deploymentFileUUID") String deploymentFileUUID, @RequestParam("deploymentName") String deploymentName) {
        return service.addDeploymentByFileNameBPMN(deploymentFileUUID, deploymentName);

    }


    //添加流程定义，通过在线提交bpmn文件
    @PostMapping(value = "/addDeploymentByString")
    public ReturnMessage<Object> addDeploymentByString(@RequestParam("stringBPMN") String stringBPMN
            , @RequestParam("deploymentName") String deploymentName) {

        return service.addDeploymentByString(stringBPMN, deploymentName);

    }


    //import org.activiti.engine.RepositoryService;
    @GetMapping(value = "/getDefinitions")
    public ReturnMessage<Object> getDefinitions() {

        return service.getDefinitions();


    }

    //获取流程定义XML
    @GetMapping(value = "/getDefinitionXML")
    public void getProcessDefineXML(HttpServletResponse response,
                                    @RequestParam("deploymentId") String deploymentId,
                                    @RequestParam("resourceName") String resourceName) {

        service.getProcessDefineXML(response, deploymentId, resourceName);

    }


    @GetMapping(value = "/getDeployments")
    public ReturnMessage<Object> getDeployments() {


        return service.getDeployments();

    }


    //删除流程定义
    @GetMapping(value = "/delDefinition")
    public ReturnMessage<Object> delDefinition(@RequestParam("depID") String depID, @RequestParam("pdID") String pdID) {
        return service.delDefinition(depID, pdID);
    }

    //删除流程定义
    @GetMapping(value = "/delDefinition2")
    public ReturnMessage<Object> delDefinitionWithNotPdId(@RequestParam("depID") String depID) {

        return service.delDefinitionWithNotPdId(depID);
    }


}
